package com.team.recovery.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * RabbitMQ延迟队列配置
 */
@Configuration
public class RabbitMQConfig {
    public static final String RESCUE_DELAY_QUEUE = "rescue.delay.queue";
    public static final String RESCUE_DELAY_EXCHANGE = "rescue.delay.exchange";
    public static final String RESCUE_DELAY_ROUTING_KEY = "rescue.delay.routing";

    @Bean
    public Queue rescueDelayQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", RESCUE_DELAY_EXCHANGE);
        args.put("x-dead-letter-routing-key", RESCUE_DELAY_ROUTING_KEY);
        args.put("x-message-ttl", 5 * 60 * 1000); // 默认5分钟
        return new Queue(RESCUE_DELAY_QUEUE, true, false, false, args);
    }

    @Bean
    public DirectExchange rescueDelayExchange() {
        return new DirectExchange(RESCUE_DELAY_EXCHANGE);
    }

    @Bean
    public Binding rescueDelayBinding() {
        return BindingBuilder.bind(rescueDelayQueue()).to(rescueDelayExchange()).with(RESCUE_DELAY_ROUTING_KEY);
    }
} 